let cinemaDao = require("../Dao/cinemaDao.js")
let ResultUtil = require("../util/ResultUtil.js")

async function getCinema(filter,page=1,limit=10,sort="_id"){
    let data = await cinemaDao.getCinema(filter,page,limit,sort);
    let count = await cinemaDao.cinemaCount(filter)
    let result = ResultUtil(data,count);
    console.log("----------"+result);
    return result;
}

/* 添加 */

async function addCinema(cinema){
   let result = await cinemaDao.addCinemas(cinema)
   console.log(result);
   if(result._id){
      return {
         code:200,
         msg:"添加成功"
      }
   }
   else{
      return {
         code:-1,
         msg:"添加失败"
      }
   }
}

/* 删除 */

async function deleteById(id){
   let result = await cinemaDao.deleteById(id)
   console.log(result);
   if(result.deletedCount>=1){
    return {code :200,msg:"删除成功"}
   }
   else{
    return {code :-1,msg:"删除失败"};
   }
}

/* 修改 */

async function updateCinema(id,cinema){
   let result = await cinemaDao.updateCinema(id,cinema)
    return result;
}

async function screen(_id){
  let result = await cinemaDao.screen(_id)
  return result
}
module.exports.getCinema = getCinema
module.exports.addCinema = addCinema
module.exports.deleteById = deleteById
module.exports.updateCinema = updateCinema
module.exports.screen = screen




